<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../../../own/lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="../../../own/css/public.css" media="all">
    <style>
        body {
            background-color: #ffffff;
        }
    </style>
</head>
<body>

    <div class="layui-form layuimini-form" lay-filter="updateSubmit">
        <input type="hidden" name="id">
        <div class="layui-form-item">
            <label class="layui-form-label required">车位号</label>
            <div class="layui-input-block">
                <input type="text" name="carnum" lay-verify="required" lay-reqtext="不能为空"
                       placeholder="请输入车位编号" value="" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label required">业主</label>
            <div class="layui-input-block">
                <input type="text" name="caruser" lay-verify="required" lay-reqtext="不能为空"
                       placeholder="请输入业主" value="" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">开始时间</label>
            <div class="layui-inline">
                <input type="date" name="starttime" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">结束时间</label>
            <div class="layui-inline">
                <input type="date" name="endtime" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label required">金额</label>
            <div class="layui-inline">
                <input type="text" name="money" lay-verify="required" lay-reqtext="不能为空"
                       placeholder="请输入金额" value="" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item" >
            <label class="layui-form-label required">缴费状态</label>
            <input type="checkbox" name="status" lay-skin="switch" lay-skin="switch" lay-filter="oc" lay-text="已缴费|未缴费">

        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn layui-btn-normal" lay-submit lay-filter="updateSubmit">确认修改</button>
            </div>
        </div>
    </div>
<script src="../../../own/lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script>
    layui.use(['form','jquery'], function () {
        var form = layui.form,
            layer = layui.layer,
            $ = layui.jquery;

        var id = parent.id;
        console.log(id)



        $.get('/user?method=selectParkById', {id}, function (res) {
            if (res.code == 0) {
                var dt = res.data;
                console.log("dt=" + dt)
                if (res.data.status == "已缴费") {
                    res.data.status=true;
                    console.log(res.data.status)
                }else {
                    res.data.status=false;
                }
                //表单数据回显
                form.val("updateSubmit", dt)
                //重新渲染表单  避免表单控件无法显示
                form.render();
            } else {
                layer.msg(res.msg, {icon: 2})
            }
        }, 'JSON')


        form.render();
        form.on('submit(updateSubmit)', function (data) {
            if (data.field.status == "on"){
                data.field.status = "已缴费";
            }else {
                data.field.status = "未缴费";
            }

            var user = JSON.stringify(data.field);
            console.log(user)
            $.post('/user?method=updateCarInfo',{user},function (res){
                if (res.code == 200){
                    layer.msg(res.msg,function (){
                        parent.window.location.reload();
                        var iframeIndex=parent.layer.getFrameIndex(window.name);
                        parent.layer.close(iframeIndex);
                    })

                }else {
                    layer.msg(res.msg,{icon: 2})
                }
            })
            return false;
        });

    });
</script>
</body>
</html>